package com.kasax.plugin.app.visitor.addLog

import com.kasax.plugin.app.LogUtils
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes


class AdddLogInitMethodVisitor extends MethodVisitor {
    String TAG = "AdddLogInitMethodVisitor"

    AdddLogInitMethodVisitor(MethodVisitor methodVisitor) {
        super(Opcodes.ASM7, methodVisitor)
    }

    @Override
    void visitCode() {
        super.visitCode()
        LogUtils.d(TAG, "visitCode start...")
        //方法执行前插入
        mv.visitLdcInsn("zzg")
        mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder")
        mv.visitInsn(Opcodes.DUP)
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false)
        mv.visitLdcInsn("into ")
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)
        mv.visitVarInsn(Opcodes.ALOAD, 0)
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false)
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getSimpleName", "()Ljava/lang/String;", false)
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false)
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "com/kasax/basiclib/MyLog",
                "logD",
                "(Ljava/lang/String;Ljava/lang/String;)V", false)
        LogUtils.d(TAG, "visitCode complete...")

    }
}